import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provide/provide.dart';
import '../../provide/cart.dart';
//import '../../model/cartInfo.dart';



class CardBottom extends StatelessWidget {
  const CardBottom({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      width: ScreenUtil().setWidth(750.0),
      padding: EdgeInsets.all(5.0),
      color: Colors.white,
      child: Provide<CartProvide>(
        builder: (context,child,childProvide){
          return Row(
            children: <Widget>[
              _selectAllBtn(context),
              _allPriceArae(context),
              _goButton(context)
            ],
         );
        },
      )
    );
  }

  //全选
  Widget _selectAllBtn(context){
    return Container(
      child: Row(
        children: <Widget>[
          Checkbox(
            value:Provide.value<CartProvide>(context).isAllCheck,
            activeColor: Colors.pink,
            onChanged: (bool value){
              Provide.value<CartProvide>(context).changeAllCheckBtnState(value);
            },
          ),
          Text('全选')
        ],
      ),
    );
  }
  //合计
  Widget _allPriceArae(context){
    double allPrice = Provide.value<CartProvide>(context).allPrice;
    return Expanded(
      child:Container(
        child: Column(
          children: <Widget>[
            Container(
              alignment: Alignment.centerRight,
              child: Text.rich(
                TextSpan(
                  children: [
                    TextSpan(
                      text: "合计: ",
                      style: TextStyle(
                        color: Colors.black,
                        fontSize: ScreenUtil().setSp(32.0)
                      )
                    ),
                    TextSpan(
                      text: "￥$allPrice",
                      style: TextStyle(
                        color: Colors.red,
                        fontSize: ScreenUtil().setSp(30.0)
                      )
                    ),
                  ]
                )
              ),
            ),
            Container(
              alignment: Alignment.centerRight,
              child:Text(
                '满10免费配送，预购免配送费',
                style:TextStyle(
                  fontSize: ScreenUtil().setSp(22)
                )
              ) ,
            )
          ],
        ),
      ) ,
    );

  }

  //结算
  Widget _goButton(context){
    int allGoodCount = Provide.value<CartProvide>(context).allGoodCount;
    return Container(
      width: ScreenUtil().setWidth(180),
      padding: EdgeInsets.only(left: 10.0),
      child: InkWell(
        onTap: null,
        child: Container(
          padding: EdgeInsets.all(10.0),
          alignment: Alignment.center,
          decoration: BoxDecoration(
            color:Colors.red,
            borderRadius: BorderRadius.all(Radius.circular(3.0)),
          ),
          child: Text(
            '结算($allGoodCount)',
            style: TextStyle(
              color:Colors.white
            ),
          ),
        )
      ),
    );
  }

}




